package org.ihelpuoo.weboo.action.http.session;

import java.util.Locale;


import org.ihelpuoo.weboo.Weboo;
import org.ihelpuoo.weboo.action.http.AjaxAction;
import org.ihelpuoo.weboo.module.ActionContext;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class SetSessionLocale extends AjaxAction
{

	@Override
	protected Object doAjax(ActionContext context) throws Exception
	{
		String localeName = context.params().getString("locale");
		Locale l = context.getAvaiableLocale(localeName);
		context.getSession().setLocale(l);
		Document doc = context.newDocument();
		Element ele = doc.createElement("OK");
		ele.setTextContent(l == null ? Weboo.DEFAULT_LOCALE_NAME : l.toString());
		doc.appendChild(ele);
		return doc;
	}

}
